﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using ApartmentBillsManager.Start.Manager;
using ApartmentBillsManager.Start.Properties;

namespace ApartmentBillsManager.Start
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            MainWindow = new Window();

            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            KeyValueConfigurationCollection settings = config.AppSettings.Settings;

            var language = settings["Language"].Value;

            LoadLanguageResourceDictionary(language);

            MainWindow.Title = "Apartment Bills Manager";

            var managerMainWindow = new ManagerMainWindow();

            MainWindow.Content = managerMainWindow;

            MainWindow.WindowState = WindowState.Maximized;

            MainWindow.Show();
        }

        private void LoadLanguageResourceDictionary(string language)
        {

            switch (language)
            {
                case "English":
                    //Current.Resources.Source = new Uri(@"Views\EnglishResourceDictionary.xaml", UriKind.Relative);
                    Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri(@"Views\EnglishResourceDictionary.xaml", UriKind.Relative) });
                    break;
                case "Hebrew": 
                    //Current.Resources.Source = new Uri(@"Views\HebrewResourceDictionary.xaml", UriKind.Relative);
                    Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri(@"Views\HebrewResourceDictionary.xaml", UriKind.Relative) });
                    break;
                default:
                    Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri(@"Views\EnglishResourceDictionary.xaml", UriKind.Relative) });
                    break;
            }
        }
    }
}
